import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/11/5 22:27
 */
public class Test3 {
    public static void main(String[] args) throws InterruptedException {
        //构造10个选手跑步比赛
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(()->{
                try {
                    Thread.sleep(3000);
                    System.out.println(Thread.currentThread().getName()+"到达终点！");

                    latch.countDown();//个数达到一致就返回了

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            t.start();
        }
        //裁判等待所有选手
      latch.await();
        System.out.println("比赛结束！");
    }
}
